﻿CREATE PROCEDURE dbo.s_CallBackConditions
@LoanID int,
@Checked bit = 0
AS	/* SET NOCOUNT ON */


IF @Checked = 0
	SELECT ID,
				 CASE IsCustom WHEN 0 THEN DescToBroker ELSE '' END Lable,
				 CASE IsCustom WHEN 1 THEN DescToBroker	 ELSE '' END LableEdit
	FROM VerificationTree_Sec(@LoanID,DEFAULT)
	WHERE IsParent = 0 AND Checked = @Checked	AND ParentID = dbo.config_ver_CallBackID()
	ORDER BY WorkFlowIndex, IsParent, TabIndex
ELSE BEGIN

	DECLARE @MenuID int SELECT @MenuID = StatusID FROM t_VerificationSmart WHERE LoanID = @LoanID
	DECLARE @T TABLE(ID int,Lable nvarchar(128),Checked bit)
	
	INSERT INTO @T
	SELECT ID, Lable,Checked FROM VerificationTree_Sec(@LoanID,DEFAULT)
		 WHERE IsParent = 0	AND ParentID = dbo.config_ver_CallBackID()
		 ORDER BY WorkFlowIndex, IsParent, TabIndex

	SELECT ID, Lable FROM @T WHERE Checked = @Checked	
	UNION ALL
	SELECT 0,REPLICATE('-',ISNULL((SELECT MAX(LEN(Lable)) FROM t_Verification_CustomHistory WHERE MenuID =@MenuID),20))
	UNION ALL
	SELECT 0,Lable FROM t_Verification_CustomHistory
	WHERE MenuID =@MenuID AND NOT Lable IN (SELECT Lable FROM @T)

END


